<html>
<head>
<title>The VOLATILE keyword.</title>
<script language="JavaScript">
</script>
</head>
<body bgcolor="#ffffcc">
<hr>
<center><h1>The VOLATILE keyword.</h1></center>
<hr>
I have had several sugestions on how to describe volatile, 
If you have any input please mail me.
<ul>
<li>The <b>volatile</b> <a href="../glossary.html#keyword">keyword</a> acts as a 
<a href="../CONCEPT/data_types.html">data type</a> qualifier. 
The qualifier alters the default why in which 
the compiler handles the variable and does not attempt to optimize the 
storage referenced by it. <i>Martin Leslie</i>
<p>
<li><b>volatile</b> means the storage is likely to change at anytime 
and be changed but something outside the control of the user program.
This means that if you reference the variable,
the program should always check the physical address (ie a mapped input fifo),
and not use it in a cashed way.<i>Stephen Hunt</i>
<p>
<li>Here is an example for the usage of the volatile keyword:
<pre>
	/* Base address of the data input latch */

	volatile unsigned char *baseAddr;

	/* read parts of output latch */

	lsb    = *handle-&gt;baseAddr;
	middle = *handle-&gt;baseAddr;
	msb    = *handle-&gt;baseAddr;
</pre>
Between reads the bytes are changed in the latch.
<p>
Without the volatile, the compiler optimises this to a single assignment:
<pre>
	lsb = middle = msb = *handle-&gt;baseAddr;
</pre>
<i>Tim Potter</i>
<p>
<li>A <b>volatile</b> variable is  for dynamic use. E.G. for data that is to
be passed to an I/O port Here is an example.

<pre>
	#define TTYPORT 0x17755U

	volatile char *port17 = (char)*TTYPORT;
	*port17 = 'o';
	*port17 = 'N';
</pre>
Without the <b>volatile</b> modifier, the compiler would think that the
statement <code>*port17 = 'o';</code> is redundant and would remove it 
from the object code. The volatile statement prevents the compiler 
optimisation.<i>Alex Arzon</i>.
</ul>

<hr>
<h2>Examples:</h2>
<a href="../EXAMPLES/volatile.c">
<img src="../../GRAPHICS/computer.gif" align=left alt="o"></a> No example:-( 
<br clear=left>
<hr>
<h2>See also:</h2>
<ul>
<li><a href="../CONCEPT/data_types.html#qualifier">const qualifier</a>
</ul>

 
<p>

<hr>
<p>
<center>
<table border=2 width="80%" bgcolor="ivory">
<tr align=center>
<td width="25%">
<a href="../cref.html">                  Top</a>
</td><td width="25%">
<a href="../master_index.html">          Master Index</a>
</td><td width="25%">
<a href="keywords.html">                 Keywords</a>
</td><td width="25%">
<a href="../FUNCTIONS/funcref.htm">      Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address><a href="../../address.html">Martin Leslie</a> 
</address><p>
</body>
</html>
